package exam.test14;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Endstart
 * Date: 2020-11-20
 * Time: 11:02
 */
public class Main {
    public static void main(String[] args) {
//      foobr(4);

//        Map<Integer, String> map = new HashMap<>();
//        map.put(11, "a");
//        map.put(null, "c");
//        map.put(null, null);
//        System.out.println(map.size());
//        System.out.println(map);

//        List<String> common.list = new ArrayList<>();
//        common.list.add("a");
//        common.list.add("b");
//        for (Iterator<String> iterator = common.list.iterator(); ; iterator.hasNext()) {
//            System.out.println(iterator.next());
//            common.list.add("c");
//        }

        Map<String, String> map = new HashMap<>();
        map.put(new String("a"), "audi");
        map.put(new String("a"), "ferrari");
        System.out.println(map);
    }

    public static void foobr(int i) {
        if (i > 0) {
            if (i % 2 == 0) {
                System.out.print("even ");
            } else {
                System.out.print("odd ");
            }
            foobr(i - 1);
            foobr(i / 2);
        }
    }

    public static List<Integer> duplicateList(ArrayList<Integer> sortList) {
        List<Integer> list = new ArrayList<>();
        Integer value = null;
        boolean alone = true;
        for (Integer integer : sortList) {
            if (value == null) {
                value = integer;
                continue;
            }

            if (value.equals(integer)) {
                if (alone) {
                    list.add(value);
                    alone = false;
                }
            } else {
                value = integer;
                alone = true;
            }

        }
        return list;
    }

    public static boolean isIsomorphic(String str1, String str2) {
        if (str1 == null || str2 == null) {
            return false;
        }
        if (str1.length() != str2.length()) {
            return false;
        }
        if (str1.length() == 0) {
            return true;
        }
        Map<Character, Character> transferMap = new HashMap<>();
        for (int i = 0; i < str1.length(); i++) {
            char ch1 = str1.charAt(i);
            char ch2 = str2.charAt(i);
            Character transferTmp = transferMap.get(ch1);
            if (transferTmp != null && transferTmp != ch2) {
                return false;
            }
            transferMap.put(ch1, ch2);
        }
        return true;
    }
}
